Operators are 'things' that do 'things' to 'things'. He he. Ok that was a little too vague a definition. It will become clear to you from the examples below. They basically perform operations on values. They have many functions and are classified accordingly. They may be used to perform mathematical operations, evaluate a condition etc. They are always used with
Statements. The mIRC Help File lists a table of operators but they are kind of incomplete for a beginner. So I have created my own list with a slightly different way of classification.
Arithmetic Operators
All the arithmetic operators in mIRC are used within the $calc() identifier. You don't use them like in other programming languages.
+ Addition.
- Subtraction.
* Multiplication.
/ Division.
% Modulo.
Maybe some of the newbies are not aware of the Modulo operator. It returns the remainder when the first operator is divided by the second operand an integral number of times. This particular operator needs special coverage because of two reasons. First, many people are encountering this operator for the first time. Second, because mIRC variables use the % sign which can confuse the
$calc() identifier.
When performing the modulo operation always make sure the operator has spaces at it's sides or else
$calc() will assume the second operand as a variable and you could get very odd results.
Don't:
$calc(5%4) // The interpreter will assume a variable named %4.
Do:
$calc(5 % 4) or
$calc(5% 4) // Notice 4 is not touching %
Note: Other operators need not have spaces at it's sides.
$calc(5+4) or
$calc(5 + 4), both are valid.
A few examples demonstrating the modulo operator in action:
$calc(5 % 4) returns 1. // 5 can be divided by 4 integrally only once and what remains is 1.
$calc(8 % 4) returns 0. // 4 divides 8 integrally twice with no remainder.
$calc(15 % 4) returns 3. // 4 can divide 15 to three integral parts (till 12). The result of 15 modulo 4 is 3. [15%4=3=15-12].
There are two special operators in mIRC which are not used within the $calc() identifier. They are used like regular operators.
// The second operator is a multiple of the first operator.
\\ The second operator is not a multiple of the first operator.
Equality and Identity Operators
== Returns true if its two operands are equal.
=== Returns true if it's two operands are identical (case-sensitive).
!= Returns true if it's two operands are not equal.
!== Returns true if it's two operands are not identical. (case-sensitive).
Side note: For those who have never programmed before, in most of the programming languages the
= sign is not the equality operator. Except in Pascal (and it's derivatives), Ada and Eiffel it's the assignment operator. That is, it's used to assign values to variables. In mIRC the use of the assignment operator is optional
var %i = 0 does the same job as
var %i 1. If you use the
= sign make sure the two operands don't touch the assignment operator or your script won't work. Those who have programmed in Bash shell will acknowledge mIRC script is similar to Bash script in many ways and one of them being this 'touchy' property. Typed language programmers should keep in mind you don't declare the variables type in mIRC. Do that and you have a buggy script.
Comparison Operators
< Less than.
> More than.
<= Less than or equal.
>= More than or equal.
Logical Operators
Logical Operators are typically used to perform "Boolean Algebra". They are used in conjugation with comparison or other evaluative operators in
if and
while statements.
&& Logical AND. Returns
true if and only if it's two operands are
true else returns
false.

Eg:
if ((%c == 24) && ($nick == %nick.002))
|| Logical OR. Returns
true if one or both of the two operands are
true else returns
false.

Eg:
if ((%i <= 10 ) && ($nick == $me))
For those curious about the logical NOT operator (
!), it's used in some operators and conditions and to check the state. For example:
if (%a != 25) echo -a %a is not equal to 25!
if (%test !alnum) echo -a %test contains things apart from letters and numbers!
if (!%lp) echo -a The variable %lp doesn't exist.
if (!$dialog(test)) echo -a The dialog named test is not open.
Alphanumerical Operators
isin The first operand is in the second operand. Eg:
if (le isin apple) echo -a It's there! | else echo -a It's not there!
isincs The first operand is in the second operand, case-sensitive. Eg:
if (lE isin apple) echo -a It's there! | else echo -a It's not there!
iswm If the first operand wildcard is in second operand. Examples:
if (*le* iswm pleees) echo -a It's there! | else echo -a It's not there!
if (Hum* iswm humanity) echo -a It's there! | else echo -a It's not there!
isnum The first operand (a number) is in the second operand (a range).

Eg:
if (4 isnum 2-9) echo -a It's there! | else echo -a It's not there!

The isnum operator can also be used to check if a value is a number. In this case it takes only the first operator.

Eg:
if (%u isnum) echo -a It's a number! | else echo -a It's not a number!

For the above example to work you should have already set a variable named %u. It's whose data value we'll be checking.
isletter The first operand (a letter) is in the second operand (a word).

Eg:
if (c isletter cat) echo -a It's there! | else echo -a It's not there!

The isletter operator can also be used to check if a value is a letter or composed of letters only.

Eg:
if (%u isletter) echo -a It's a letter! | else echo -a It's not a letter!
The following operators take only one operator.
isalnum The operand contains only letters and numbers.
isalpha The operand contains only letters.
islower The operand contains only lower case letters.
isupper The operand contains only upper case letters.
IRC Related Operators
ison A nick (the first operator) is on a channel (the second operator).
isop A nick (the first operator) is an OP on a channel (the second operator).
ishop A nick (the first operator) is a half OP on a channel (the second operator).
isvoice A nick (the first operator) is voiced on a channel (the second operator).
isreg A nick (the first operator) is a regular (normal) nick on a channel (the second operator).
ischan If you are on a channel (the first operator).
isban If an address (the first operator) is in the Internal Ban List.
isaop If a nick (the first operator) is in your auto-op list for a channel (the second parameter). The second parameter is optional.
isavoice If a nick (the first operator) is in your auto-voice list for a channel (the second parameter). The second parameter is optional.
isignore If a nick (the first operator) is in your ignore list with an ignore switch (the second parameter). The second parameter is

optional. Refer the ignore command to know more about it's switches.
isnotify If a nick (the first operator) is in your notify list.
Note: To negate an operator you prefix it with the Logical NOT (!) operator.
Two more Operators
$+ This operator concatenates the two operands. It joins the parameters before and after it. They should be separated by the space
character and may or may not be contained within an identifier. Eg:
//echo -a Spyder $+ Wares echoes "SpyderWares".
| The pipe operator. It's function is very different from the pipe in Bash, Perl etc. What it does in mIRC is equivalent to the semicolon (;)
operator in other programming languages. Not exactly to mark the end of an expression but to contain two expressions in one line.
Examples: Refer the examples for Alphanumerical Operators.
There is a special identifier
$ifmatch which returns the first operand of a matching conditional statement. Examples:
if (*itni* iswm mitnick) { echo -a $ifmatch } Retuns "*itni*".
if (pp isin apple) { echo -a $ifmatch } Returns "pp".
That was all about Operators. Next we'll take a look at Statements without which the Operators don't have any functionality. Not that Statements can be very functional without the Operators either. Both of them are interdependent.
Back
|
Table of Contents
|
Statements
Copyright © 2002-2004 SpyderWares.
Feel free to distribute this tutorial in part or whole, just make sure the credits stay intact.
http://spyderwares.com